// pages/messages/messages.js
var util = require('../../utils/util.js');
var qcloud = require('../../vendor/wafer2-client-sdk/index')
var app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    winWidth: 0,
    winHeight: 0,
    spec: 0,
    couponlist:{}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log("选择优惠券" );
    var that = this;
    that.setData({
      spec: options.spec
    });
    console.log(that.data.spec);
    util.post(app.api.getUserCouponList, { unionid: app.globalData.unionid, spec: 0}, function (res)    {
      console.log("unionid" + app.globalData.unionid);
      console.log(res);
      that.setData({
        couponList: res.data,
      });
    });
  },
  boxChange: function (e) {
    var vals = e.detail.value;
    console.log(e.detail.value);
    var total = 0;
    vals.forEach(function(v){
      total += parseFloat(v);
    });
    var pages = getCurrentPages();
    var that = this;
    var currPage = pages[pages.length - 1];  //当前页面
    var prevPage = pages[pages.length - 2]; //上一个页面
    //直接调用上一个页面的setData()方法，把数据存到上一个页面中去
    prevPage.setData({
      voucherMoney: total,
      resTotal: (that.data.spec - total)
    });
    console.log(total);
    console.log(that.data.spec);
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  }
})